package com.itheima.countroller;

import com.itheima.cammon.CommonResult;
import com.itheima.cammon.PageInof;
import com.itheima.pojo.Order;
import com.itheima.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 王同学
 */
@RestController
@RequestMapping("order")
public class OrderController {
    @Autowired
    OrderService orderService;

    //订单管理
    @GetMapping("page")
    public CommonResult order(String beginTime, String endTime, String number,
                              @RequestParam(defaultValue = "1") Integer page,
                              @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInof<Order> list = orderService.page(beginTime, endTime, number, page, pageSize);

        return CommonResult.success(list);
    }

    //订单状态修改
    @PutMapping
    public CommonResult updateStatus(@RequestBody Order order) {
        //修改状态
        boolean res = orderService.updatestatus(order.getStatus(), order.getId());
        if (!res) {
            return CommonResult.error("订单启用/禁用操作失败！！！");
        }
        return CommonResult.success("订单启用/禁用操作成功~！");
    }
}
